00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _communicator_hpp_
00021 #define _communicator_hpp_
00022
00023 #include <boost/mpi.hpp>
00024 #include <boost/shared_ptr.hpp>
00025 #include "gridpack/utilities/complex.hpp"
00026
00027 namespace gridpack {
00028 namespace parallel {
00029
00030
00031 class CommunicatorPrivate;
00032
00033
00034
00035
00036 class Communicator {
00037 public:
00038
00039
00040 Communicator(void);
00041
00042
00043 Communicator(const Communicator& old);
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 Communicator(const boost::mpi::communicator& comm);
00054
00055
00056
00057
00058
00059
00060
00061 Communicator(const MPI_Comm& comm);
00062
00063
00064 Communicator & operator=(const Communicator & rhs);
00065
00066
00067 ~Communicator(void);
00068
00069
00070 int size(void) const
00071 {
00072 return p_comm.size();
00073 }
00074
00075
00076 int rank(void) const
00077 {
00078 return p_comm.rank();
00079 }
00080
00081
00082 int worldRank(void) const;
00083
00084
00085 operator MPI_Comm() const
00086 {
00087 return static_cast<MPI_Comm>(p_comm);
00088 }
00089
00090
00091 operator boost::mpi::communicator() const
00092 {
00093 return p_comm;
00094 }
00095
00096 void barrier() const
00097 {
00098 p_comm.barrier();
00099 }
00100
00101
00102 Communicator split(int color) const
00103 {
00104 return Communicator(p_comm.split(color));
00105 }
00106
00107
00108 Communicator self(void) const
00109 {
00110 return split(this->rank());
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 Communicator divide(int nsize) const;
00122
00123
00124 const boost::mpi::communicator& getCommunicator(void) const
00125 {
00126 return p_comm;
00127 }
00128
00129
00130 int getGroup(void) const;
00131
00132
00133
00134 void sync(void) const;
00135
00136
00137
00138
00139
00140
00141 void sum(float *x, int nvals) const;
00142 void sum(double *x, int nvals) const;
00143 void sum(int *x, int nvals) const;
00144 void sum(long *x, int nvals) const;
00145 void sum(gridpack::ComplexType *x, int nvals) const;
00146
00147
00148
00149
00150
00151
00152
00153 void max(float *x, int nvals) const;
00154 void max(double *x, int nvals) const;
00155 void max(int *x, int nvals) const;
00156 void max(long *x, int nvals) const;
00157
00158
00159
00160
00161
00162
00163
00164 void min(float *x, int nvals) const;
00165 void min(double *x, int nvals) const;
00166 void min(int *x, int nvals) const;
00167 void min(long *x, int nvals) const;
00168
00169
00170 static void report(void);
00171
00172 protected:
00173
00174
00175 void swap(Communicator& other);
00176
00177
00178 boost::mpi::communicator p_comm;
00179
00180
00181 boost::shared_ptr<CommunicatorPrivate> p_private;
00182 };
00183
00184
00185 }
00186 }
00187
00188 #endif
00189